﻿Imports System.Threading.Tasks

Public Class frmWait
    Public WaitTask As Task
    Public TimeOutState As Boolean
    Private vTimeOut As Integer

    Sub New()
        InitializeComponent()
        Me.prInfo.AutoHeight = True
    End Sub

    Public Sub SetOptions(ByVal caption As String, ByVal desc As String, ByVal timeout As Integer)
        Me.prInfo.AutoHeight = True
        Me.prInfo.Caption = caption
        Me.prInfo.Description = desc
        vTimeOut = timeout
        TimeOutState = False
        If timeout < 0 Then
            WaitTask = Task.Factory.StartNew(AddressOf doWaitTask, TaskCreationOptions.LongRunning)
        End If
    End Sub

    Private Sub doWaitTask()
        Try
            WaitTask.Wait(vTimeOut)
            TimeOutState = True
            Me.Invoke(Sub() Me.Close())
        Catch ex As Exception

        End Try
    End Sub

    Public Overrides Sub SetCaption(ByVal caption As String)
        MyBase.SetCaption(caption)
        Me.prInfo.Caption = caption
    End Sub


    Public Overrides Sub SetDescription(ByVal description As String)
        MyBase.SetDescription(description)
        Me.prInfo.Description = description
    End Sub

    Public Overrides Sub ProcessCommand(ByVal cmd As System.Enum, ByVal arg As Object)
        MyBase.ProcessCommand(cmd, arg)
    End Sub

    Public Enum WaitFormCommand
        SomeCommandId
    End Enum

    Private Sub frmWait_Load(sender As Object, e As EventArgs) Handles Me.Load
        TimeOutState = False
    End Sub

End Class
